unit entYTS;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, uClassEntry, cxGraphics, cxControls,
  cxLookAndFeels, cxLookAndFeelPainters, cxContainer, cxEdit,
  cxPCdxBarPopupMenu, cxStyles, cxCustomData, cxFilter, cxData, cxDataStorage,
  Data.DB, cxDBData, Vcl.Menus, Data.Win.ADODB, Vcl.ActnList, cxPropertiesStore,
  cxHeader, Vcl.StdCtrls, cxButtons, cxGridLevel, cxClasses, cxGridCustomView,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGrid, cxPC,
  cxGroupBox, cxTextEdit, cxDBEdit, cxMaskEdit, cxSpinEdit, cxDropDownEdit,
  cxLookupEdit, cxDBLookupEdit, cxDBLookupComboBox, cxCheckBox;

type
  TfmYTS = class(TfmClassEntry)
    grdReportID: TcxGridDBColumn;
    grdReportsFirmaAdi: TcxGridDBColumn;
    grdReportsFirmaAdres: TcxGridDBColumn;
    grdReportsTelefon: TcxGridDBColumn;
    grdReportsFax: TcxGridDBColumn;
    grdReportsEmail: TcxGridDBColumn;
    grdReportsBelgeVYer: TcxGridDBColumn;
    grdReportsFirmaIL: TcxGridDBColumn;
    grdReportnServisAlani: TcxGridDBColumn;
    grdReportnPersonelSayisi: TcxGridDBColumn;
    grdReportnStatuID: TcxGridDBColumn;
    grdReportnFiyat: TcxGridDBColumn;
    grdReportbState: TcxGridDBColumn;
    edFirmaAdi: TcxDBTextEdit;
    Label1: TLabel;
    Label2: TLabel;
    edFirmaAdres: TcxDBTextEdit;
    edServisAlan: TcxDBSpinEdit;
    Label3: TLabel;
    Label4: TLabel;
    edPersonelSayisi: TcxDBSpinEdit;
    Label5: TLabel;
    edFiyat: TcxDBSpinEdit;
    cbState: TcxDBCheckBox;
    Label6: TLabel;
    aqStatu: TADOQuery;
    dsStatu: TDataSource;
    lcStatu: TcxDBLookupComboBox;
    Label7: TLabel;
    edYTS: TcxTextEdit;
    grdReportnIdariAlan: TcxGridDBColumn;
    grdReportnIdariPersonelSayisi: TcxGridDBColumn;
    Label8: TLabel;
    ediServisAlan: TcxDBSpinEdit;
    Label9: TLabel;
    ediPersonelSayisi: TcxDBSpinEdit;
    grdReportsBelgeNo: TcxGridDBColumn;
    grdReportnTopServisAlani: TcxGridDBColumn;
    grdReportnTopPersonelSayisi: TcxGridDBColumn;
    grdReportKapasite: TcxGridDBColumn;
    grdReportKullanilanKapasite: TcxGridDBColumn;
    grdReportKapasiteOran: TcxGridDBColumn;
    grdReportKullanilanServisAlani: TcxGridDBColumn;
    grdReportGerekliPersonelSayisi: TcxGridDBColumn;
    grdReportEksikPersonelSayisi: TcxGridDBColumn;
    grdReportEksikAlan: TcxGridDBColumn;
    cbHesapla: TcxCheckBox;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure acListExecute(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fmYTS: TfmYTS;

implementation

{$R *.dfm}

procedure TfmYTS.acListExecute(Sender: TObject);
var
  ExCursor: TCursor;
begin
  inherited;
  ExCursor := Screen.Cursor;
  Screen.Cursor := crSQLWait;
  try
    With aqList do
    begin
      Close;
      Sql.Text := 'SELECT Y.ID,Y.sFirmaAdi,Y.sFirmaAdres,Y.sTelefon,Y.sFax,Y.sEmail,Y.sBelgeNo,Y.sBelgeVYer,Y.sFirmaIL,Y.nServisAlani,';
      Sql.Add('Y.nPersonelSayisi,Y.nStatuID,Y.nFiyat,Y.bState,Y.nIdariAlan,Y.nIdariPersonelSayisi');
      if cbHesapla.Checked then
      begin
        Sql.Add(',nTopServisAlani=Y2.nServisAlani');
        Sql.Add(',nTopPersonelSayisi=Y2.nPersonelSayisi');
        Sql.Add(',Y2.Kapasite,Y2.KullanilanKapasite,Y2.KapasiteOran,Y2.KullanilanServisAlani,Y2.GerekliPersonelSayisi');
        Sql.Add(',Y2.EksikPersonelSayisi,Y2.EksikAlan');
      end;
      Sql.Add('FROM tbYTS Y WITH(NOLOCK)');
      if cbHesapla.Checked then
        Sql.Add('LEFT JOIN WW_YTS_DETAY Y2 WITH(NOLOCK) ON (Y.ID=Y2.ID)');
      Sql.Add('WHERE 1=1');
      if (Trim(edYTS.Text) <> '') then
        Sql.Add('AND Y.sFirmaAdi Like ''' + Trim(edYTS.Text) + '%''');
      Open;
    end;
  finally
    Screen.Cursor := ExCursor;
  end;
end;

procedure TfmYTS.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;
  Action := caFree;
  fmYTS := nil;
end;

procedure TfmYTS.FormCreate(Sender: TObject);
begin
  inherited;
  aqStatu.Close;
  aqStatu.Open;
end;

end.
